import com.mysql.cj.jdbc.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
//
//public class Test {
//    public static void main(String[] args) throws SQLException {
//        Scanner scanner = new Scanner(System.in);
//        System.out.println("input id: ");
//        int id = scanner.nextInt();
//        System.out.println("input name: ");
//        String name = scanner.next();
//
//        DataSource dataSource = new MysqlDataSource();
//        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java110?characterEncoding=utf8&useSSL=false");
//        ((MysqlDataSource) dataSource).setUser("root");
//        ((MysqlDataSource) dataSource).setPassword("abc123");
//
//        Connection connection = dataSource.getConnection();
//
//        String sql = "insert into student values(" + id + ",'" + name + "')";
//
//        PreparedStatement statement = connection.prepareStatement(sql);
//
//        int n = statement.executeUpdate();
//        System.out.println(n);
//
//        statement.close();
//        connection.close();
//    }
//}

//
//public class TestJDBCInsert {
//    public static void main(String[] args) throws SQLException {
//        Scanner scanner = new Scanner(System.in);
//        System.out.println("input id: ");
//        int id = scanner.nextInt();
//        System.out.println("input name: ");
//        String name = scanner.next();
//
//        DataSource dataSource = new MysqlDataSource();
//        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java110?characterEncoding=utf8&useSSL=false");
//        ((MysqlDataSource) dataSource).setUser("root");
//        ((MysqlDataSource) dataSource).setPassword("abc123");
//
//        Connection connection = dataSource.getConnection();
//
//        //String sql = "insert into student values(" + id + ",'" + name + "')";
//
//        String sql = "insert into student values(?,?)";
//
//        PreparedStatement statement = connection.prepareStatement(sql);
//        statement.setInt(1,id);
//        statement.setString(2,name);
//
//        int n = statement.executeUpdate();
//        System.out.println(n);
//
//        statement.close();
//        connection.close();
//    }
//}


public class TestJDBCInsert {
    public static void main(String[] args) throws SQLException {
        Scanner scanner = new Scanner(System.in);

        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java110?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("abc123");

        Connection connection = dataSource.getConnection();

        for(int i = 0;i<10000;i++) {
            String sql = "insert into student values(" + i + ",'张三')";

            PreparedStatement statement = connection.prepareStatement(sql);

            int n = statement.executeUpdate();
            //System.out.println(n);
            statement.close();
        }
        connection.close();
    }
}